import {message} from "antd";

export function markdownContent(value) {
    if (!Blob || !URL) return message.error('浏览器不支持导出md文件，请更换浏览器再试');
    if (!value) return message.warning('当前内容为空，无需导出');
    let blob = new Blob([value])
    let a = document.createElement('a')
    let downloadURL = URL.createObjectURL(blob)
    a.href = downloadURL
    a.download = `测试文件.md`
    a.click()
    URL.revokeObjectURL(downloadURL);
}

export function importMarkdown(callback) {
    if (!FileReader) return message.error('浏览器不支持导入md文件，请更换浏览器再试');
    const input = document.createElement('input')
    input.type = 'file'
    input.accept = '.md'
    input.click()
    input.addEventListener('change', () => {
        const files = input.files[0]
        const reader = new FileReader()
        reader.readAsText(files)
        reader.onload = () => {
            callback(reader.result)
        }
    })
}

